package com.infra.micro.id.fallback;

import com.infra.common.resp.Response;
import com.infra.micro.id.api.IdSnowflakeApi;
import org.springframework.cloud.openfeign.FallbackFactory;

import org.springframework.stereotype.Component;

import java.util.Set;

@Component
public class IdSnowflakeApiFallback implements FallbackFactory<IdSnowflakeApi> {
    @Override
    public IdSnowflakeApi create(Throwable cause) {
        return new IdSnowflakeApi() {
            @Override
            public Response<Long> getId(Integer appId) {
                return Response.error("服务异常[" + cause.getMessage() + "]，请联系相关服务负责人");
            }

            @Override
            public Response<Set<Long>> getId(Integer appId, int step) {
                return Response.error("服务异常[" + cause.getMessage() + "]，请联系相关服务负责人");
            }
        };
    }
}
